<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Event</title>
    <script>
        //添加on()
        function on(){
            alert("灯亮了")
        }


    </script>
</head>
<body>
   <!--通过HTML标签中的事件属性进行绑定  -->
   <input type="button" onclick="on()" value="开灯"/>
   <!--通过DOM元素属性绑定  -->
   <input type="button" id="btn" value="关灯"/>

   <script>
       var btn = document.getElementById("btn");
       btn.onclick = function (){
           alert("灯灭了")
       }
   </script>
</body>
</html>